package svc

import (
	"backend/apps/book/models"
	"backend/apps/book/rpc/internal/config"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

type ServiceContext struct {
	Config        config.Config
	AuthorModel   models.AuthorModel
	CategoryModel models.CategoryModel
	TagModel      models.TagModel
	BookModel     models.BookModel
	ChapterModel  models.ChapterModel
	ContentModel  models.ChapterContentModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	client := sqlx.NewMysql(c.MySQL.DataSource)
	return &ServiceContext{
		Config:        c,
		AuthorModel:   models.NewAuthorModel(client, c.Cache),
		CategoryModel: models.NewCategoryModel(client, c.Cache),
		TagModel:      models.NewTagModel(client, c.Cache),
		BookModel:     models.NewBookModel(client, c.Cache),
		ChapterModel:  models.NewChapterModel(client, c.Cache),
		ContentModel:  models.NewChapterContentModel(client, c.Cache),
	}
}
